package net.uni.ap.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.uni.ap.bo.BaseBo;
import net.uni.util.Page;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

/**
 * BaseAction
 * @author HeDroid
 *
 */
public class BaseAction extends ActionSupport implements SessionAware,
		ServletResponseAware, ServletRequestAware {
	private static final long serialVersionUID = 1L;
	protected Map<String,Object> session;
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	//action只进行内部forword
	protected String forwardURL;
	public void setErrorInfo(String errorMsg) {}
	/**
	 * logout，login等操作之前清除session中所有数据
	 */
	public void clearSession(){
		if(session!=null)
			session.clear();
	}


	public String doForward(){
		return SUCCESS;
	}

	/**
	 * 获取系统访问路径：http://ip:port/projectName
	 * @return
	 */
	public String getBasePath(){
		return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() +  request.getContextPath() + "/";
	}

	
	/**
	 * @param key
	 * @return
	 * @方法说明  return this.getRequest().getParameter("key");
	 * @date 2011-11-14
	 * @author 孙伟
	 */
	public String getValue(String key){
		return this.getRequest().getParameter(key);
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request=request;
	}
	
	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response=response;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session=session;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public String getForwardURL() {
		return forwardURL;
	}

	public void setForwardURL(String forwardURL) {
		this.forwardURL = forwardURL;
	}
	
	Page page = new Page();
	private BaseBo baseService;
	
	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}
	public void setBaseService(BaseBo baseService) {
		this.baseService = baseService;
	}
	public String testSpringHibernateStruts(){
		page = baseService.testBo();
		
		return SUCCESS;
	}
	
}
